import os
from conf import conf
import subprocess
def generate_random_128bit_binaries(n, filepath):
    with open(filepath, 'wb') as f:
        for _ in range(n):
            random_bytes = os.urandom(16)  # 128 位 = 16 字节
            f.write(random_bytes)

def work():
    base_dir = os.path.dirname(os.path.abspath(__file__)).replace('\\', '/') + "/../../"
    config = conf.read_json()
    num = config['bucket_num']+3 # 生成随机数矩阵t0;
    subprocess.run([base_dir+"bin/random_t0.exe",str(num),base_dir+"data/client/t0.bin"], capture_output=True)

    # generate_random_128bit_binaries(num, base_dir+"data/client/t0.bin")
    result = subprocess.run([base_dir+"bin/linear_cli.exe",
                             base_dir+"data/client/cuckoo.bin",
                             base_dir+"data/client/linear.bin"], capture_output=True)
    print("线性映射完成") # 输出错误信息
    print(result.stdout.decode()) # 输出结果
    if result.returncode!=0:
         return False
    result = subprocess.run([base_dir+"bin/xor.exe",
                             base_dir+"data/client/t0.bin",
                             base_dir+"data/client/linear.bin",
                             base_dir+"data/client/t1.bin"], capture_output=True)
    print("异或运算完成") # 输出错误信息
    print(result.stdout.decode()) # 输出结果
    if result.returncode!=0:
         return False
    return True

if __name__ == '__main__':
    work()